import com.java.demo.Articles;
import com.java.demo.UConfig;
import com.java.demo.User;
import com.java.demo.controller.UserController;
import com.java.demo.model.ArticleInfo;
import com.java.demo.service.UserService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class App {
    public static void main(String[] args) {
        //1.得到上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//           BeanFactory context2 = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        //2.得到bean对象
        // 通过名称获取
          User user = (User) context.getBean("user");
        UserController userController = context.getBean("userController",UserController.class);
        //通过类型获取
//            User user = context.getBean(User.class);
        //通过名称+类型获取
//        User user = context.getBean("user", User.class);
//        UserService userService = context.getBean("userService", UserService.class);
//        UConfig uConfig = context.getBean("UConfig",UConfig.class);
//        ArticleInfo articleInfo = context.getBean("articleInfo",ArticleInfo.class);
//        Articles articles = context.getBean("articles",Articles.class);

        //3.使用bean对象
         user.sayHi();
//         userController.sayHi();
//        userService.sayHi();
//        uConfig.sayHi();
//        System.out.println(articleInfo.toString());
//        articles.sayHi();

    }
}
